using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Codex
{
    public class Tag : IComparable, IComparer
    {
        private string label, fieldName, fieldValue, type;

        public Tag()
        {
            type = "label";
            label = "";
        }

        public Tag(string _label)
        {
            type = "label";
            label = _label;
        }

        public Tag(string _fieldName, string _fieldValue)
        {
            type = "field";
            fieldName = _fieldName;
            fieldValue = _fieldValue;
        }

        public void setTagType(string _type) { type = _type; }
        public void setLabel(string _label)
        {
            type = "label";
            label = _label;
        }
        public void setFieldName(string _fieldName)
        {
            type = "field";
            fieldName = _fieldName;
        }
        public void setFieldValue(string _fieldValue)
        {
            type = "field";
            fieldValue = _fieldValue;
        }

        public string getType() { return type; }
        public string getLabel() { return label; }
        public string getFieldName() { return fieldName; }
        public string getFieldValue() { return fieldValue; }

        public override string ToString()
        {
            switch (type)
            {
                case "label":
                    return label;
                case "field":
                    return fieldName + ":" + fieldValue;
            }

            return "error in Tag.cs: bad tag type: " + type;
        }

        public int CompareTo(Object compareObject)
        {
            if (compareObject is Tag)
            {
                Tag compareTag = (Tag)compareObject;

                return (int)(this.type.CompareTo(compareTag.type)
                +   this.label.CompareTo(compareTag.label)
                +   this.fieldName.CompareTo(compareTag.fieldName)
                +   this.fieldValue.CompareTo(compareTag.fieldValue));
            }
            else
            {
                throw new ArgumentException("object is not a Tag");
            }
        }

        public int Compare(Object compareObject1, Object compareObject2)
        {
            if (compareObject1 is Tag && compareObject2 is Tag)
            {
                Tag compareTag1 = (Tag)compareObject1;
                Tag compareTag2 = (Tag)compareObject2;

                return compareTag1.CompareTo(compareTag2);
            }
            else throw new ArgumentException("one of two objects being compared is not a NetNode");
        }
    }
}
